from qiniu import Auth, put_data

# access_key = "cOHVAF0aKxB8dAwdkxABxlFSCpiW0bhRQaw0lsQf"
# secret_key = "VvPBoqE_pH6RNdQvEZCAoOx2oVtgsinxVY9TwfZq"
# q = Auth(access_key,secret_key)


QINIU_DOMAIN = "http://qhq9d7bnb.hn-bkt.clouddn.com"
#

def upload_qiniu(filestorage,image_filename):
    access_key = "cOHVAF0aKxB8dAwdkxABxlFSCpiW0bhRQaw0lsQf"
    secret_key = "VvPBoqE_pH6RNdQvEZCAoOx2oVtgsinxVY9TwfZq"

    # 构建鉴权对象
    q = Auth(access_key, secret_key)

    # 要上传的空间
    bucket_name = "cow1"

    # 设置 上传之后保存文件的名字
    filename = 'weitezh_' + image_filename

    # 生成上传 Token，可以指定过期时间等
    token = q.upload_token(bucket_name, filename, 3600)

    # put_file()
    ret, info = put_data(token, filename, filestorage.read())

    if info.status_code == 200:
        url = QINIU_DOMAIN +'/' +filename

        return url
    return None
